home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Misc / DXDiagOutput / DxDiagOutput.cpp next >
Encoding:
C/C++ Source or Header  |  2004-09-30  |  6.8 KB  |  190 lines

  1. //----------------------------------------------------------------------------
  2. // File: DxDiagOutput.cpp
  3. //
  4. // Desc: Sample app to read info from dxdiagn.dll by enumeration
  5. //
  6. // Copyright (c) Microsoft Corp. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #define INITGUID
  9. #include <windows.h>
  10. #include <stdio.h>
  11. #include <assert.h>
  12. #include <initguid.h>
  13. #include <dxdiag.h>
  14.  
  15.  
  16.  
  17.  
  18. //-----------------------------------------------------------------------------
  19. // Defines, and constants
  20. //-----------------------------------------------------------------------------
  21. #define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
  22. #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
  23. #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
  24.  
  25.  
  26.  
  27.  
  28. //-----------------------------------------------------------------------------
  29. // Function-prototypes
  30. //-----------------------------------------------------------------------------
  31. HRESULT PrintContainerAndChildren( WCHAR* wszParentName, IDxDiagContainer* pDxDiagContainer );
  32.  
  33.  
  34.  
  35.  
  36. //-----------------------------------------------------------------------------
  37. // Name: main()
  38. // Desc: Entry point for the application.  We use just the console window
  39. //-----------------------------------------------------------------------------
  40. int main(int argc, char* argv[])
  41. {
  42.     HRESULT       hr;
  43.  
  44.     CoInitialize( NULL );
  45.  
  46.     IDxDiagProvider*  pDxDiagProvider = NULL;
  47.     IDxDiagContainer* pDxDiagRoot = NULL;
  48.  
  49.     // CoCreate a IDxDiagProvider*
  50.     hr = CoCreateInstance( CLSID_DxDiagProvider,
  51.                            NULL,
  52.                            CLSCTX_INPROC_SERVER,
  53.                            IID_IDxDiagProvider,
  54.                            (LPVOID*) &pDxDiagProvider);
  55.     if( SUCCEEDED(hr) ) // if FAILED(hr) then dx9 is not installed
  56.     {
  57.         // Fill out a DXDIAG_INIT_PARAMS struct and pass it to IDxDiagContainer::Initialize
  58.         // Passing in TRUE for bAllowWHQLChecks, allows dxdiag to check if drivers are 
  59.         // digital signed as logo'd by WHQL which may connect via internet to update 
  60.         // WHQL certificates.    
  61.         DXDIAG_INIT_PARAMS dxDiagInitParam;
  62.         ZeroMemory( &dxDiagInitParam, sizeof(DXDIAG_INIT_PARAMS) );
  63.  
  64.         dxDiagInitParam.dwSize                  = sizeof(DXDIAG_INIT_PARAMS);
  65.         dxDiagInitParam.dwDxDiagHeaderVersion   = DXDIAG_DX9_SDK_VERSION;
  66.         dxDiagInitParam.bAllowWHQLChecks        = TRUE;
  67.         dxDiagInitParam.pReserved               = NULL;
  68.  
  69.         hr = pDxDiagProvider->Initialize( &dxDiagInitParam );
  70.         if( FAILED(hr) ) 
  71.             goto LCleanup;
  72.  
  73.         hr = pDxDiagProvider->GetRootContainer( &pDxDiagRoot );
  74.         if( FAILED(hr) ) 
  75.             goto LCleanup;
  76.  
  77.         // This function will recursivly print the properties
  78.         // the root node and all its child.
  79.         hr = PrintContainerAndChildren( NULL, pDxDiagRoot );
  80.         if( FAILED(hr) ) 
  81.             goto LCleanup;
  82.     }
  83.  
  84. LCleanup:
  85.     SAFE_RELEASE( pDxDiagRoot );
  86.     SAFE_RELEASE( pDxDiagProvider );
  87.     
  88.     CoUninitialize();
  89.     
  90.     return 0;
  91. }
  92.  
  93.  
  94.  
  95.  
  96. //-----------------------------------------------------------------------------
  97. // Name: PrintContainerAndChildren()
  98. // Desc: Recursivly print the properties the root node and all its child
  99. //       to the console window
  100. //-----------------------------------------------------------------------------
  101. HRESULT PrintContainerAndChildren( WCHAR* wszParentName, IDxDiagContainer* pDxDiagContainer )
  102. {
  103.     HRESULT hr;
  104.  
  105.     DWORD dwPropCount;
  106.     DWORD dwPropIndex;
  107.     WCHAR wszPropName[256];
  108.     VARIANT var;
  109.     WCHAR wszPropValue[256];
  110.  
  111.     DWORD dwChildCount;
  112.     DWORD dwChildIndex;
  113.     WCHAR wszChildName[256];
  114.     IDxDiagContainer* pChildContainer = NULL;
  115.  
  116.     VariantInit( &var );
  117.  
  118.     hr = pDxDiagContainer->GetNumberOfProps( &dwPropCount );
  119.     if( SUCCEEDED(hr) ) 
  120.     {
  121.         // Print each property in this container
  122.         for( dwPropIndex = 0; dwPropIndex < dwPropCount; dwPropIndex++ )
  123.         {
  124.             hr = pDxDiagContainer->EnumPropNames( dwPropIndex, wszPropName, 256 );
  125.             if( SUCCEEDED(hr) )
  126.             {
  127.                 hr = pDxDiagContainer->GetProp( wszPropName, &var );
  128.                 if( SUCCEEDED(hr) )
  129.                 {
  130.                     // Switch off the type.  There's 4 different types:
  131.                     switch( var.vt )
  132.                     {
  133.                         case VT_UI4:
  134.                             swprintf( wszPropValue, L"%d", var.ulVal );
  135.                             break;
  136.                         case VT_I4:
  137.                             swprintf( wszPropValue, L"%d", var.lVal );
  138.                             break;
  139.                         case VT_BOOL:
  140.                             wcscpy( wszPropValue, (var.boolVal) ? L"true" : L"false" );
  141.                             break;
  142.                         case VT_BSTR:
  143.                             wcsncpy( wszPropValue, var.bstrVal, 255 );
  144.                             wszPropValue[255] = 0;
  145.                             break;
  146.                     }
  147.  
  148.                     // Add the parent name to the front if there's one, so that
  149.                     // its easier to read on the screen
  150.                     if( wszParentName )
  151.                         wprintf( L"%s.%s = %s\n", wszParentName, wszPropName, wszPropValue );
  152.                     else
  153.                         wprintf( L"%s = %s\n", wszPropName, wszPropValue );
  154.  
  155.                     // Clear the variant (this is needed to free BSTR memory)
  156.                     VariantClear( &var );
  157.                 }
  158.             }
  159.         }
  160.     }
  161.  
  162.     // Recursivly call this function for each of its child containers
  163.     hr = pDxDiagContainer->GetNumberOfChildContainers( &dwChildCount );
  164.     if( SUCCEEDED(hr) )
  165.     {
  166.         for( dwChildIndex = 0; dwChildIndex < dwChildCount; dwChildIndex++ )
  167.         {
  168.             hr = pDxDiagContainer->EnumChildContainerNames( dwChildIndex, wszChildName, 256 );
  169.             if( SUCCEEDED(hr) )
  170.             {
  171.                 hr = pDxDiagContainer->GetChildContainer( wszChildName, &pChildContainer );
  172.                 if( SUCCEEDED(hr) )
  173.                 {
  174.                     // wszFullChildName isn't needed but is used for text output 
  175.                     WCHAR wszFullChildName[256];
  176.                     if( wszParentName )
  177.                         swprintf( wszFullChildName, L"%s.%s", wszParentName, wszChildName );
  178.                     else
  179.                         wcscpy( wszFullChildName, wszChildName );
  180.                     PrintContainerAndChildren( wszFullChildName, pChildContainer );
  181.  
  182.                     SAFE_RELEASE( pChildContainer );
  183.                 }
  184.             }
  185.         }
  186.     }
  187.     
  188.     return S_OK;
  189. }
  190.